{% extends "base.html" %}
{% block body %}
<div class="card border border-dark shadow bg-card-body" id="tasks_div" style="resize:vertical;margin-top:5px">
    <div class="card-header bg-header text-white border border-dark shadow" >
        <span style="display:inline-block">
            <h2 style="display:inline-block"><span class="operator">Active</span> and <font color="bg-warning">Inactive</font> Callbacks</h2>
        </span>
        <span style="display:inline-block; float:right">
            <span class="input-group" >
            <input class="form-control" style="color:white" type="text" size="50rem" placeholder="Filter Callbacks by hostname with regex" id="filter" @keyup.enter="filter()">
            <div class="input-group-append input-group-btn" ><button  type="button" class="btn btn-secondary" @click="filter()"><i class="fa fa-search"></i></button></div>
            </span>
        </span>
    </div>
    <div style="overflow-y:auto;height:calc(80vh)" >
        <div v-for="callback in callbacks" class="card bg-card-body border-dark border-bottom-0 border-top-0 border-right-0 rounded-0 shadow" id="'callback'+callback.id" :key="callback.id" style="padding:5px">
            <div :class="callback.active ? 'card-header bg-header-dark border border-dark shadow' : 'card-header bg-header-dark border border-dark shadow'">
                <template v-if="callback.active"><span class="operator">Tasks for Callback <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/split_callbacks/' + callback.id" target="_blank">[[callback.id]]</a>:</span></template>
                <template v-else><font color="bg-warning">Tasks for Callback <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/split_callbacks/' + callback.id" target="_blank">[[callback.id]]</a>:</font></template>
                [[callback.user]]@[[callback.host]] with pid ([[callback.pid]])
                <button v-if="callback.hasOwnProperty('tasks')" class="btn btn-sm btn{{config['outline-buttons']}}info" @click="load_tasks(callback)">Hide Tasks</button>
                <button v-else class="btn btn-sm btn{{config['outline-buttons']}}secondary" @click="load_tasks(callback)">Load Tasks</button>
                <button v-if="!callback.active" class="btn btn-sm btn{{config['outline-buttons']}}secondary" @click="make_active(callback)">Make Callback Active</button>
                <span style="float:right">[[callback.description]]</span>
            </div>
            <div v-if="callback.hasOwnProperty('tasks')">
                <div v-for="(task,i) in callback.tasks" :key="task.id" style="word-wrap: break-word;overflow-y:auto">
                    <div class="card-header border-dark bg-header-dark" :key="'headera' + task.id" style="position:-webkit-sticky;position:static;top:0;padding-bottom:0;padding-top:0px;padding-left:0;white-space:nowrap;overflow-x:auto;max-width:100%">
                        <transition-group>
                     <button v-if="task.comment != '' && task.comment_visible" :key="'keya' + task.id" class="btn btn{{config['outline-buttons']}}danger btn-sm" @click="remove_comment(task)" style="padding:0px 4px;margin-left:2px;margin-top:2px;border:0"><i class="fas fa-trash-alt"></i></button>
                     <p v-if="task.comment != '' && task.comment_visible" :key="'keyb' + task.id" class="card-text" style="margin:0;display:inline-block">
                        <small class="text-muted">[[task.comment_operator]]'s comment:</small></p>
                     <pre v-if="task.comment != '' && task.comment_visible" :key="'keyc' + task.id" style="padding-left:27px">[[task.comment]]</pre>
                     <hr v-if="task.comment != '' && task.comment_visible" :key="'keyd' + task.id" style="margin-bottom: 0;margin-top:6px">

                     <div class="btn-group dropdown" :key="'statusdropdown' + task.id" style="display:inline-block;">
                        <template v-if="task.opsec_pre_blocked === true && task.opsec_pre_bypassed === false">
                                 <button class="btn btn{{config['outline-buttons']}}warning btn-sm dropdown-toggle" style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">OPSEC BLOCKED (PRE)</span></button>
                             </template>
                             <template v-else-if="task.opsec_post_blocked === true && task.opsec_post_bypassed === false">
                                 <button class="btn btn{{config['outline-buttons']}}warning btn-sm dropdown-toggle" style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">OPSEC BLOCKED (POST)</span></button>
                             </template>
                            <template v-else-if="task.status.includes('error')">
                                <button class="btn btn{{config['outline-buttons']}}danger btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>
                            <template v-else-if="task.completed == true || task.status === 'completed'">
                                <button class="btn btn{{config['outline-buttons']}}success btn-sm dropdown-toggle" style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">completed</span></button>
                            </template>
                            <template v-else-if="task.status == 'processed'">
                                <button class="btn btn{{config['outline-buttons']}}primary btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>
                            <template v-else-if="task.status == 'processing' || task.status == 'cleared'">
                                <button class="btn btn{{config['outline-buttons']}}warning btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>

                            <template v-else>
                                <button class="btn btn{{config['outline-buttons']}}info btn-sm dropdown-toggle"  style="border:0" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="card-text">[[task.status]]</span></button>
                            </template>
                        <div class="dropdown-menu" style="z-index:9999">
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="Add comment to task" @click="add_comment(task)"><i class="fas fa-comments"></i> Comment</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="download raw output" @click="download_raw_output(task.id)"><i class="fas fa-save"></i> Save Output</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="Copy command to clipboard" @click="copyStringToClipboard(task.command + ' ' + task.original_params)"><i class="far fa-copy" ></i> Copy Command</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="Toggle application of browser scripts to output of this task" @click="task.use_scripted = !task.use_scripted"><i class="fas fa-code"></i>
                                <template v-if="task.use_scripted">
                                    Disable Browser Script
                                </template>
                                <template v-else>
                                    Enable Browser Script
                                </template>
                            </a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="View Stdout/Stderr for task" @click="view_stdout_stderr(task)"><i class="fas fa-info-circle"></i>View Task Stdout/Stderr</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="View all parameters for task" @click="view_all_parameters(task)"><i class="fas fa-info-circle"></i>View All Parameters</a>
                            <a class="dropdown-item" href="#" data-toggle="tooltip" title="View/Edit all tags for task" @click="view_all_tags(task)"><i class="fas fa-edit"></i>View/Edit Tags</a>
                            <template v-if="task.opsec_pre_blocked !== null || task.opsec_post_blocked !== null">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="View OPSEC block info" @click="view_opsec_block(task)"><i class="fas fa-info-circle"></i>View OPSEC Message</a>
                            </template>
                            <template v-if="task.opsec_pre_blocked && task.opsec_pre_bypassed === false">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="submit bypass request" @click="submit_opsec_bypass_request(task)"><i class="fas fa-info-circle"></i>Submit Bypass Request ([[task.opsec_pre_bypass_role]])</a>
                            </template>
                            <template v-else-if="task.opsec_post_blocked && task.opsec_post_bypassed === false">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="submit bypass request" @click="submit_opsec_bypass_request(task)"><i class="fas fa-info-circle"></i>Submit Bypass Request ([[task.opsec_post_bypass_role]])</a>
                            </template>
                            <template v-if="task.status === 'error: container down'">
                                <a class="dropdown-item" href="#" data-toggle="tooltip" title="re-issue request" @click="reissue_request(task)"><i class="fas fa-info-circle"></i> Re-issue task</a>
                            </template>
                        </div>
                    </div>
                     <p :key="'mutedtext' + task.id" class="card-text" style="margin:0;padding-left:5px; display:inline-block"><small class="text-muted">
                        [[task.operator]]'s task: <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + task.id" target="_blank" data-toggle="tooltip" title="View task and output in a separate window">[[task.id]] </a> <template v-if="task.parent_task !== null">(subtask of <a :href="'{{http}}://{{links.server_ip}}:{{links.server_port}}/tasks/' + task.parent_task" target="_blank" data-toggle="tooltip" title="View task and output in a separate window">[[task.parent_task]]</a>)</template>
                        - at [[toLocalTime(task.timestamp)]]
                     </small></p>
                     <a :key="'commentdots' + task.id" v-if="task.comment !== ''" style="padding-bottom:0" class="btn btn-link" type="button" @click="toggle_comment(task)"><i class="far fa-comment-dots" ></i></a>
                     <br :key="'br' + task.id">
                     <a :key="'toggleoutput' + task.id" class="btn btn-link" type="button" style="border:0;padding:0 0 5px 5px" data-toggle="collapse" :data-target="'#cardbody' + task.id" aria-expanded="false" :aria-controls="'cardbody' + task.id" @click="toggle_arrow(task)"><i :id="'color-arrow' + task.id" class="fas fa-plus fa-xs" data-toggle="tooltip" title="view / hide task output"></i></a>
                        <div style="display:inline-block" :key="'taskcommand' + task.id"><b>&nbsp;[[task.command]]&nbsp;</b></div>
                     <div style="display:inline-block" :key="'taskparams' + task.id">[[task.display_params]]</div>
                    </transition-group>
                    </div>
                    <div :key="'outputcontent' + task.id" class="collapse" :id="'cardbody' + task.id" >
            <div :key="'outputcontentcardbody' + task.id" class="response-background card-body shadow" style="padding-top:0;padding-bottom: 0" >
                <div :key="'showparams' + task.id" v-if="task.show_params">
                    Modified Parameters: &nbsp;[[task.params]]
                </div>
                <span :key="'usescripted' + task.id" v-if="task.hasOwnProperty('scripted') && task.use_scripted" v-html="task.scripted"></span>
                <span v-else :key="'useregular' + task.id" class="card-text" v-for="rsp in task.response" :key="rsp.id" :id="'response' + rsp.id" style="white-space: pre-wrap"><span class="response"><pre>[[rsp.response]]</pre></span></span>
            </div>
    </div>
                </div>
            </div>
    </div>
    </div>

    <div class="card-footer bg-card-footer">
        <div style="display:inline-block">
            <button type="button" :disabled="current_page <= 1" class="btn btn-light" data-toggle="tooltip" title="Go back one page" @click="get_page(current_page-1)"><i class="fas fa-backward"></i></button>&nbsp;
            <template v-if="current_page > 1">
                <button type="button" class="btn btn-light" data-toggle="tooltip" title="Go to first page" @click="get_page(1)">1</button>
            </template>
            <template v-if="current_page > 2">&nbsp;<font size="5" class="text-white">...</font>&nbsp;</template>
            <template v-if="current_page -2 > 1">
                <button type="button" class="btn btn-light" @click="get_page(current_page -2)">[[current_page - 2]]</button>
            </template>
            <template v-if="current_page -1 > 1">
                <button type="button" class="btn btn-light" @click="get_page(current_page -1)">[[current_page - 1]]</button>
            </template>
            <button type="button" disabled class=" btn btn-light" data-toggle="tooltip" title="Current page">[[current_page]] </button>
            <template v-if="current_page + 1 < Math.ceil(total_count/page_size)">
                <button type="button" class="btn btn-light" @click="get_page(current_page + 1)">[[current_page + 1]]</button>
            </template>
            <template v-if="current_page + 2 < Math.ceil(total_count/page_size)">
                <button type="button" class="btn btn-light" @click="get_page(current_page +2)">[[current_page + 2]]</button>
            </template>
            <template v-if="current_page < Math.ceil(total_count/page_size) -1">
                &nbsp;<font size="5" class="text-white">...</font>&nbsp;
            </template>
            <template v-if="current_page != Math.ceil(total_count/page_size)  && total_count > 0">
                <button type="button" class="btn btn-light" data-toggle="tooltip" title="Go to last page" @click="get_page(Math.ceil(total_count/page_size))">[[Math.ceil(total_count/page_size)]]</button>
            </template>

            <button type="button" class="btn btn-light" :disabled="current_page == Math.ceil(total_count/page_size) || Math.ceil(total_count/page_size) == 0" data-toggle="tooltip" title="Go forward one page" @click="get_page(current_page + 1)"><i class="fas fa-forward"></i></button>
            &nbsp;<font size="4" class="text-white">Total Count: [[total_count]]</font>
        </div>

        <div style="display:inline-block; float:right">
            <span class="input-group">
            <input class="form-control" type="number" size="10rem" :placeholder="page_size" id="page_size" @keyup.enter="get_new_page_size()">
            <div class="input-group-append input-group-btn" ><button  type="button" class="btn btn{{config['outline-buttons']}}success" @click="get_new_page_size()">Edit page size</button></div>
            </span>
        </div>
    </div>
</div>
<!-- THIS IS OUR MODAL FOR ADDING A COMMENT -->
<div class="modal fade" id="addCommentModal" role="dialog" >
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3>Add / Edit Comment</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
            Shift+Enter to add a new line, Enter to submit
              <div class="modal-body">
                <textarea class="form-control" rows="25" style="width:100%" id="addCommentTextArea"></textarea>
              </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}success" data-dismiss="modal" id="addCommentSubmit" aria-hidden="true">Submit</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR ADDING A COMMENT -->
<!-- THIS IS OUR MODAL FOR ADDING A TAG -->
<div class="modal fade" id="addTagModal" role="dialog" >
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content" id="addTagModalData">
            <div class="modal-header bg-dark text-white">
                <h3>Add / Edit Tags</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
            Shift+Enter to add a new line when manually entering, or click "+" to add the selected tag:
            <span class="input-group" >
                <select class="form-control" v-model="selected_tag" style="width:auto;display:inline-block">
                    <option  v-for="o in tags" :value="o">[[ o ]]</option>
                </select>
                <button style="display:inline-block;float:right" class="btn btn-sm btn{{config['outline-buttons']}}success" @click="tasks_div.add_tag()"><i class="fas fa-plus"></i></button>
            </span>
          <div class="modal-body">
            <textarea class="form-control" rows="25" style="width:100%"  v-model="current_tags" id="addTagTextArea"></textarea>
          </div>
          <div class="modal-footer">
              <button class="btn btn{{config['outline-buttons']}}warning" data-dismiss="modal" aria-hidden="true">Cancel</button>
              <button class="btn btn{{config['outline-buttons']}}success" data-dismiss="modal" id="addTagSubmit" aria-hidden="true">Submit</button>
          </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR ADDING A TAG -->

{% endblock %}
{% block scripts %}
{% include "view_tasks.js" %}
{% endblock %}

{% block body_config %}

{% endblock %}